<?php
namespace classlib\core;
require 'view/abstract.int.php';
use classlib\core\view\view_abstract;
class view {
	/**
	 * 工厂函数获取视图
	 * @param string $view 需要获取的视图引擎
	 * @return view_abstract $view 缓存实例
	 */
	public static function inst($view='') {
		if (!$view) {
			$path = isset($_SERVER['PATH_INFO'])? 'PATH_INFO':'REQUEST_URI';
			$npos = strrpos($_SERVER[$path], '.');
			$view = ($npos)? substr($_SERVER[$path], $npos+1):'html';
			if (!file_exists(__DIR__.'/view/'.$view.'.cls.php')) {
				$view = 'html';
			}
		}
		$class = 'classlib\core\view\\'.$view;
		$view = new $class;
		return $view;
	}
}
